package com.ruoyi.production.service.impl.greenhousefilm;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.production.mapper.greenhousefilm.GreenhousefilmAmountMapper;
import com.ruoyi.production.domain.greenhousefilm.GreenhousefilmAmount;
import com.ruoyi.production.service.greenhousefilm.IGreenhousefilmAmountService;

/**
 * 棚膜量Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@Service
public class GreenhousefilmAmountServiceImpl implements IGreenhousefilmAmountService
{
    @Autowired
    private GreenhousefilmAmountMapper greenhousefilmAmountMapper;

    /**
     * 查询棚膜量
     *
     * @param greenhousefilmAmountId 棚膜量ID
     * @return 棚膜量
     */
    @Override
    public GreenhousefilmAmount selectGreenhousefilmAmountById(Long greenhousefilmAmountId)
    {
        return greenhousefilmAmountMapper.selectGreenhousefilmAmountById(greenhousefilmAmountId);
    }

    /**
     * 查询棚膜量列表
     *
     * @param greenhousefilmAmount 棚膜量
     * @return 棚膜量
     */
    @Override
    public List<GreenhousefilmAmount> selectGreenhousefilmAmountList(GreenhousefilmAmount greenhousefilmAmount)
    {
        return greenhousefilmAmountMapper.selectGreenhousefilmAmountList(greenhousefilmAmount);
    }

    /**
     * 新增棚膜量
     *
     * @param greenhousefilmAmount 棚膜量
     * @return 结果
     */
    @Override
    public int insertGreenhousefilmAmount(GreenhousefilmAmount greenhousefilmAmount)
    {
        greenhousefilmAmount.setCreateTime(DateUtils.getNowDate());
        greenhousefilmAmount.setCreateTime(DateUtils.getNowDate());
//        向已有的数据直接在原来的基础上添加库存
        int r =greenhousefilmAmountMapper.updateGreenhousefilmAmount1(greenhousefilmAmount);
        if(r==0) {
            //        若原来的上面没有，则新加数据
            return greenhousefilmAmountMapper.insertGreenhousefilmAmount(greenhousefilmAmount);
        }
        return 1;
    }

    /**
     * 修改棚膜量
     *
     * @param greenhousefilmAmount 棚膜量
     * @return 结果
     */
    @Override
    public int updateGreenhousefilmAmount(GreenhousefilmAmount greenhousefilmAmount)
    {
        greenhousefilmAmount.setUpdateTime(DateUtils.getNowDate());
        //        删除这条数据，将这条数据当作新数据处理
        greenhousefilmAmountMapper.deleteGreenhousefilmAmountById(greenhousefilmAmount.getGreenhousefilmAmountId());
        //        若原来已有的数据，则向已有的数据直接在原来的基础上添加库存
        int r =greenhousefilmAmountMapper.updateGreenhousefilmAmount1(greenhousefilmAmount);
        if(r==0){
            //        若原来的上面没有，则当作新数据插入
            return greenhousefilmAmountMapper.insertGreenhousefilmAmount(greenhousefilmAmount);
        }
        return 1;
    }

    /**
     * 批量删除棚膜量
     *
     * @param greenhousefilmAmountIds 需要删除的棚膜量ID
     * @return 结果
     */
    @Override
    public int deleteGreenhousefilmAmountByIds(Long[] greenhousefilmAmountIds)
    {
        return greenhousefilmAmountMapper.deleteGreenhousefilmAmountByIds(greenhousefilmAmountIds);
    }

    /**
     * 删除棚膜量信息
     *
     * @param greenhousefilmAmountId 棚膜量ID
     * @return 结果
     */
    @Override
    public int deleteGreenhousefilmAmountById(Long greenhousefilmAmountId)
    {
        return greenhousefilmAmountMapper.deleteGreenhousefilmAmountById(greenhousefilmAmountId);
    }
}
